package com.whu.helpluojia.service.impl;

import com.whu.helpluojia.domain.Bagman;
import com.whu.helpluojia.domain.MyPublish;
import com.whu.helpluojia.domain.Supply;
import com.whu.helpluojia.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class MyDetailServiceImpl implements MyDetailService {

    @Autowired
    BagManService bagManService;

    @Autowired
    FindService findService;

    @Autowired
    LostAndFoundService lostAndFoundService;

    @Autowired
    SupplyService supplyService;

    @Autowired
    ConsultService consultService;

    @Override
    public List<MyPublish> getMypublishments(Long userId) {

        List<MyPublish> list1 = bagManService.getMyDetail(userId);

        List<MyPublish> list2 = findService.getMyDetail(userId);

        List<MyPublish> list3 = lostAndFoundService.getMyDetail(userId);

        List<MyPublish> list4 = supplyService.getMyDetail(userId);

        List<MyPublish> list5 = consultService.getMyDetail(userId);

        List<MyPublish> myPublishList = Stream.of(list1, list2, list3, list4, list5).
                flatMap(Collection::stream).collect(Collectors.toList());
        Collections.reverse(myPublishList);//时间倒序
        return myPublishList;
    }
}
